<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xStockbuy.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted,computed } from 'vue'
import baTableClass from '/@/utils/baTable'
import { xStockbuy,dEPARTMENT,authAdmin } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const route = useRoute()
const isApproval = computed(()=> {
    return route.name === "xStockApproval"
})

const { t } = useI18n()
const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(xStockbuy,isApproval.value?'_s':undefined),
    {
        pk: 'BIZNO',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('xStockbuy.BIZNO'), prop: 'BIZNO', align: 'center' },
            { label: t('xStockbuy.FITTING'), prop: 'FITTING', align: 'center' },
            { label: t('xStockbuy.STOCKAREA'), prop: 'STOCKAREA', align: 'center', show: false },
            { label: t('xStockbuy.BRAND'), prop: 'BRAND', align: 'center', show: false },
            { label: t('xStockbuy.SPECS'), prop: 'SPECS', align: 'center', show: false },
            { label: t('xStockbuy.CONTAINER'), prop: 'CONTAINER', align: 'center' },
            { label: t('xStockbuy.PRICE'), prop: 'PRICE', align: 'center', operator: 'RANGE' },
            { label: t('xStockbuy.NUMBER'), prop: 'NUMBER', align: 'center', operator: 'RANGE' },
            { label: t('xStockbuy.SQR'), prop: 'SQR', align: 'center',comSearchRender: 'remoteSelect', remote: {
                pk: 'nickname',
                field: 'nickname',
                remoteUrl:authAdmin+'index',
                params: {},
            } },
            { label: t('xStockbuy.DEPT'), prop: 'DEPTNAME', align: 'center',operator:false },
            { label: t('xStockbuy.DEPT'), prop: 'DEPT', align: 'center',show:false,comSearchRender: 'remoteSelect', remote: {
                pk:'DEPTID',
                field: 'DEPTNAME',
                remoteUrl:dEPARTMENT +'index',
                params: {},
            } },
            { label: t('xStockbuy.SQDATE'), prop: 'SQDATE', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            { label: t('xStockbuy.OP'), prop: 'OP', align: 'center', show: false,comSearchRender: 'remoteSelect', remote: {
                pk: 'nickname',
                field: 'nickname',
                remoteUrl:authAdmin+'index',
                params: {},
            } },
            { label: t('xStockbuy.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160, show: false },
            { label: t('xStockbuy.REMARK'), prop: 'REMARK', align: 'center', show: false },
            { label: '审批状态', prop: 'status', align: 'center', render:'tag',operator:'=',replaceValue:{'未发起':'未发起','待审批':'待审批','已审批':'已审批','已退回':'已退回','已完成':'已完成'}},
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false, },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'BIZNO', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)
console.log(baTable.form);
provide('baTable', baTable)




onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
export default defineComponent({
    name: 'xStockbuy',
})
</script>

<style scoped lang="scss"></style>
